package com.tedu.announce.controller;

import com.tedu.announce.pojo.dto.AnnounceQuery;
import com.tedu.announce.pojo.vo.AnnounceVO;
import com.tedu.announce.service.AnnounceService;
import com.tedu.common.response.JsonResult;
import com.tedu.user.pojo.dto.AnnounceSaveParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/p1/announce")
public class AnnounceController {

    @Autowired
    private AnnounceService announceService;

    @GetMapping("/select")
    public JsonResult selectAnnounce(AnnounceQuery announceQuery) {
        log.debug("查询公告-入参：{}", announceQuery);
        List<AnnounceVO> announce = announceService.selectAnnounce(announceQuery);
        log.debug("查询公告-出参：{}", announce);
        return JsonResult.ok(announce);
    }

    @DeleteMapping("/delete/{id}")
    public JsonResult deleteAnnounce(@PathVariable Integer id) {
        log.debug("删除公告-入参：{}",id);
        announceService.deleteAnnounce(id);
        return JsonResult.ok();
    }

    @PostMapping("/save")
    public JsonResult addAnnounce(AnnounceSaveParam announceSaveParam){
        log.debug("新增公告-入参：{}",announceSaveParam);
        announceService.addAnnounce(announceSaveParam);
        return JsonResult.ok();
    }

}
